﻿using Microsoft.Extensions.Logging;
using Quartz;
using System;
using System.Threading.Tasks;

namespace NetCore.Quartz.Job
{
    /// <summary>
    /// 员工工资计算
    /// </summary>
    public class EmployeeSalaryCalculationJob : IJob
    {
        private readonly ILogger<EmployeeSalaryCalculationJob> _logger;

        //private readonly IOrder_layerwindingmachineequipmentRepository _order_LayerwindingmachineequipmentRepository;
        //private readonly IOrderDrawingequipmentRepository _orderDrawingequipmentRepository;
        //private readonly IEmployeeSalaryCalculationServices _employeeSalaryCalculationServices;
        public EmployeeSalaryCalculationJob(ILogger<EmployeeSalaryCalculationJob> logger)//, IOrder_layerwindingmachineequipmentRepository order_LayerwindingmachineequipmentRepository, IOrderDrawingequipmentRepository orderDrawingequipmentRepository,IEmployeeSalaryCalculationServices employeeSalaryCalculationServices
        {
            _logger = logger;
            //_order_LayerwindingmachineequipmentRepository = order_LayerwindingmachineequipmentRepository;
            //_orderDrawingequipmentRepository = orderDrawingequipmentRepository;
            //_employeeSalaryCalculationServices = employeeSalaryCalculationServices;
        }

        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                #region 添加数据

                //int count = 0;
                //int equipmentId = 1;
                //long orderDrawingequipmentId = 0;
                //int shiftId = 0;
                //int userid = 0;

                //int spoolRfid = 1;

                //List<DateTime> dateTimes = new List<DateTime>();
                //for (int datetime9 = 1; datetime9 <= 30; datetime9++)
                //{
                //    dateTimes.Add(new DateTime(2021, 9, datetime9, 8, 0, 0));
                //}
                //for (int datetime10 = 1; datetime10 <= 31; datetime10++)
                //{
                //    dateTimes.Add(new DateTime(2021, 10, datetime10, 14, 0, 0));
                //}
                //for (int datetime11 = 1; datetime11 <= 25; datetime11++)
                //{
                //    dateTimes.Add(new DateTime(2021, 11, datetime11, 23, 0, 0));
                //}
                //foreach (DateTime dateTime in dateTimes)
                //{
                //    for (int u = 0; u < 6; u++)
                //    {
                //        switch (u)
                //        {
                //            case 0:
                //                userid = 1;
                //                break;
                //            case 1:
                //                userid = 3362;
                //                break;
                //            case 2:
                //                userid = 3364;
                //                break;
                //            case 3:
                //                userid = 3365;
                //                break;
                //            case 4:
                //                userid = 3367;
                //                break;
                //            case 5:
                //                userid = 3371;
                //                break;
                //        }
                //        for (int i = 1; i <= 3; i++)
                //        {
                //            if (dateTime.Hour >= 6 && dateTime.Hour < 12)
                //                shiftId = 5;
                //            else if (dateTime.Hour >= 13 && dateTime.Hour < 17)
                //                shiftId = 6;
                //            else if ((dateTime.Hour >= 17 && dateTime.Hour < 24) || (dateTime.Hour >= 0 && dateTime.Hour < 6))
                //                shiftId = 7;

                //            OrderDrawingequipmentBak orderDrawingequipment = new OrderDrawingequipmentBak()
                //            {
                //                HeatNumber = "" + i,
                //                BatchNumber = "xxxx",
                //                SpoolRfid = spoolRfid + "RFID_" + TimeHelper.ToUnixTimestampByMilliseconds(DateTime.Now),
                //                EquipmentId = equipmentId,
                //                RawmaterialId = equipmentId,
                //                ShiftId = shiftId,
                //                Weight = "0",
                //                Yield = "0",
                //                Userid = userid,
                //                ProductionTime = dateTime
                //            };
                //            spoolRfid++;

                //            if (spoolRfid == 23)
                //                spoolRfid = 1;
                //            orderDrawingequipmentId = await _orderDrawingequipmentRepository.AddOrderDrawingequipmentBak(orderDrawingequipment);

                //            if (orderDrawingequipmentId <= 0)
                //                return;
                //            if (equipmentId == 4)
                //                equipmentId = 1;
                //            else
                //                equipmentId = equipmentId + 1;
                //            await Console.Out.WriteLineAsync(DateTime.Now + ":添加成功(大)");
                //            for (int j = 1; j <= 84; j++)
                //            {
                //                if (DateTime.Now.Hour >= 6 && DateTime.Now.Hour < 12)
                //                    shiftId = 5;
                //                else if (DateTime.Now.Hour >= 13 && DateTime.Now.Hour < 17)
                //                    shiftId = 6;
                //                else if ((DateTime.Now.Hour >= 17 && DateTime.Now.Hour < 24) || (DateTime.Now.Hour >= 0 && DateTime.Now.Hour < 6))
                //                    shiftId = 7;
                //                int qualifiedproducts = 1;

                //                if (j % 5 == 0)
                //                    qualifiedproducts = 2;
                //                OrderLayerwindingmachineequipmentrBak orderLayerwindingmachineequipmentrBak = new OrderLayerwindingmachineequipmentrBak()
                //                {
                //                    DiscNumber = "" + count,
                //                    EquipmentId = equipmentId,
                //                    RawmaterialId = equipmentId,
                //                    OrderDrawingequipmentId = orderDrawingequipmentId,
                //                    ShiftId = shiftId,
                //                    Weight = "555",
                //                    Userid = userid,
                //                    WoodenPalletNo = "2",
                //                    ProductionTime = dateTime,
                //                    RunTime = "1111",
                //                    ProductionproductId = equipmentId,
                //                    Qualifiedproducts = qualifiedproducts
                //                };
                //                count++;
                //                long id = await _order_LayerwindingmachineequipmentRepository.AddOrder_LayerwindingmachineEquipmentr_Bak(orderLayerwindingmachineequipmentrBak);
                //                await Console.Out.WriteLineAsync(DateTime.Now + ":添加成功" + id);
                //            }
                //        }
                //    }

                //}

                #endregion 添加数据

                #region 员工工资统计

                //if (await _employeeSalaryCalculationServices.StatisticsEmployeeWages())
                //    await Console.Out.WriteLineAsync(DateTime.Now + "：计算员工工资成功");

                #endregion 员工工资统计

                await Console.Out.WriteLineAsync(DateTime.Now + "：任务执行成功。");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
            }
        }
    }
}